import { cooperationBehavior } from "../../../../behaviors/cooperation";
import { getActiveStr } from "../../../../utils/utilsNew";
const computedBehavior = require('miniprogram-computed')
Component({
  behaviors: [cooperationBehavior, computedBehavior],
  /**
   * 组件的属性列表
   */
  properties: {
    cooperationId:String,
    userID: String,
    isMine:  Boolean,
    targetAvatar: String,
    mineAvatar: String,
  },

  options: {
    styleIsolation: "apply-shared",
    addGlobalClass: true,
  },

  /**
   * 组件的初始数据
   */
  data: {
    model: {},
    wechatUnionid:'',
    _cooperationId: '', //缓存
  },
  lifetimes: {
    attached: function () {
      let avatar = this.data.isMine ? this.data.mineAvatar : this.data.targetAvatar;
      this.setData({
        avatar: avatar || "/images/default_head.png",
      });
    },

    detached: function () {
      // 在组件实例被从页面节点树移除时执行
    },
  },

  observers: {
    cooperationId(cooperationId) {
      if (!cooperationId) return;
      if (this.data._cooperationId == cooperationId) return;
      this.data._cooperationId = cooperationId;

      this.getInfoByCooperationId(cooperationId).then((content) => {
        
        if (!content) return
        const vo = { ...content.hmCooperationDelVO }
        vo._imgUrl = content.houImageVO.length!==0? content.houImageVO[0].url:'/images/defaultImgSmall.jpg'
        vo._resblockName = getActiveStr(vo.title, 22)
        vo._prices = vo.delegationType=='SALES'? (vo.totalPrices)/10000 : vo.totalPrices
        vo._unit = vo.delegationType=='SALES'? '万' : '元'
        vo._houseInfo = `${vo.room}室${vo.hall}厅/${vo.buildSize}㎡/${vo.area}`
        vo._address = vo.city + vo.area + vo.addr
        this.setData({
          model: vo,
          wechatUnionid: content.jjrVO.wechatUnionid
        });
        
      })
    }
  },
  /**
   * 组件的方法列表
   */
  methods: {
    gotoHouseInfo(){
      if(this.data.wechatUnionid!==this.data.userID){
        wx.navigateTo({
          url: `/pages/house/RentalHouseDetail/teamworkHouseDetail/teamworkHouseDetail?cooperationId=${this.data.cooperationId}`,
        });
      } else {
        wx.navigateTo({
          url: `/pages/house/RentalHouseDetail/coopertionHouseInfo/coopertionHouseInfo?cooperationId=${this.data.cooperationId}`,
        });
      }
    }
  }
})
